package daniel.k.supportdesigndemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class SnackBarActivity extends Activity {
    @ViewInject(R.id.tv_top_right)
    TextView tv_top_right;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_snack_bar);
        ViewUtils.inject(this);
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @OnClick({R.id.tv_top_right})
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.tv_top_right:
                TextView tv = (TextView) v;
                //创建一个Snackbar
                Snackbar snackbar = Snackbar.make(v, tv.getText() + " onClick", Snackbar.LENGTH_INDEFINITE);
                snackbar.setDuration(10000);
                //Snackbar设置Action，添加textview后边的按钮
                snackbar.setAction("onClick1", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        System.out.println("onClick action onclick!");
                    }
                });
                snackbar.setAction("onClick2", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        System.out.println("onClick2 action onclick!");
                    }
                });
                snackbar.setCallback(new Snackbar.Callback()
                {
                    public void onDismissed(Snackbar snackbar, int event){
                        System.out.println(event);
                    }
                    public void onShown(Snackbar snackbar){
                        System.out.println("Snackbar now is onShow.");
                    }
                });
                snackbar.show();
                break;

            default:
                break;
        }
    }

}
